/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Utilities;

import org.neuroph.util.TransferFunctionType;

/**
 *
 * @author Celso
 */
public class Tradutor {

    Integer hiddenNeurons;
    TransferFunctionType transferFunctionType;
    Double learnRate;
    Double momentum;

    public void translate(String candidate) {

        defineTransferFunction(codeToReal(candidate.substring(0, 7)));
        defineHiddenNeurons(codeToReal(candidate.substring(7, 14)));
        learnRate = codeToReal(candidate.substring(14, 21));
        momentum = codeToReal(candidate.substring(21, 28));

    }

    // transform a number from binary to real
    private Double codeToReal(String var) {
        return Integer.parseInt(var, 2) / 127.0;

    }

    private void defineTransferFunction(Double v) {
        this.transferFunctionType = TransferFunctionType.SIGMOID;
        if (v > .5) {
            this.transferFunctionType = TransferFunctionType.TANH;

        }

    }

    private void defineHiddenNeurons(Double codeToReal) {
        this.hiddenNeurons = Math.round((float) (codeToReal * 100));

    }

    public Integer getHiddenNeurons() {
        return hiddenNeurons;
    }

    public TransferFunctionType getTransferFunctionType() {
        return transferFunctionType;
    }

    public Double getLearnRate() {
        return learnRate;
    }

    public Double getMomentum() {
        return momentum;
    }

}
